package com.ruoyi.web.controller.information;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.information.domain.InterviewQuestion;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.information.domain.InterviewRecord;
import com.ruoyi.information.service.IInterviewRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模拟面试记录
Controller
 * 
 * @author Ly
 * @date 2025-06-16
 */
@RestController
@RequestMapping("/information/record")
public class InterviewRecordController extends BaseController
{
    //  模拟面试记录Service
    @Autowired
    private IInterviewRecordService interviewRecordService;

    /**
     * 查询模拟面试记录
列表
     */
    @PreAuthorize("@ss.hasPermi('information:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(InterviewRecord interviewRecord)
    {
        startPage();
        List<InterviewRecord> list = interviewRecordService.selectInterviewRecordList(interviewRecord);
        return getDataTable(list);
    }

    /**
     * 导出模拟面试记录
列表
     */
    @PreAuthorize("@ss.hasPermi('information:record:export')")
    @Log(title = "模拟面试记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InterviewRecord interviewRecord)
    {
        List<InterviewRecord> list = interviewRecordService.selectInterviewRecordList(interviewRecord);
        ExcelUtil<InterviewRecord> util = new ExcelUtil<InterviewRecord>(InterviewRecord.class);
        util.exportExcel(response, list, "模拟面试记录数据");
    }

    /**
     * 获取模拟面试记录
详细信息
     */
    @PreAuthorize("@ss.hasPermi('information:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(interviewRecordService.selectInterviewRecordById(id));
    }

    /**
     * 新增模拟面试记录

     */
    @PreAuthorize("@ss.hasPermi('information:record:add')")
    @Log(title = "模拟面试记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InterviewRecord interviewRecord)
    {
        return toAjax(interviewRecordService.insertInterviewRecord(interviewRecord));
    }

    /**
     * 修改模拟面试记录

     */
    @PreAuthorize("@ss.hasPermi('information:record:edit')")
    @Log(title = "模拟面试记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InterviewRecord interviewRecord)
    {
        return toAjax(interviewRecordService.updateInterviewRecord(interviewRecord));
    }

    /**
     * 删除模拟面试记录

     */
    @PreAuthorize("@ss.hasPermi('information:record:remove')")
    @Log(title = "模拟面试记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(interviewRecordService.deleteInterviewRecordByIds(ids));
    }

    /**
     * 开始面试
     */
    @GetMapping("/start")
    public AjaxResult StartInterview(Long recordId)
    {
        List<InterviewQuestion> list = interviewRecordService.start(recordId);
        return AjaxResult.success(list);
    }

    /**
     * 结束面试
     */
    @GetMapping("/end")
    public AjaxResult EndInterview(Long recordId)
    {
        List<InterviewQuestion> list = interviewRecordService.end(recordId);
        return AjaxResult.success(list);
    }
}
